# -*- coding: utf8 -*-

import sys
import time
import pickle


def profile(func):
    def wrapper(*args, **kwargs):
        started_at = time.time()
        sys.stderr.write('Profile start: {}\n'.format(func.__name__))
        result = func(*args, **kwargs)
        sys.stderr.write('Profile finish: {}, time: {:.3f} sec.\n'.format(func.__name__, time.time() - started_at))
        return result
    return wrapper


def deprecated(func):
    def wrapper(*args, **kwargs):
        sys.stderr.write('{} function is deprecated'.format(func.__name__))
        return func(*args, **kwargs)
    return wrapper


@profile
def dump_object(obj, filename):
    with open(filename, 'wb') as handle:
        pickle.dump(obj, handle)


@profile
def load_object(filename):
    with open(filename, 'rb') as handle:
        return pickle.load(handle)
